from aiogram_dialog import DialogManager
from sqlalchemy.ext.asyncio import AsyncSession

from src.application.order.service import OrderService
from src.application.server.enums import ServerPrivacy, ServerType
from src.infrastructure.db.services.servers import get_server


async def server_type_getter(db_session: AsyncSession, dialog_manager: DialogManager, **kwargs):
    order_id: int = dialog_manager.start_data.get("order_id")
    order_service: OrderService = dialog_manager.middleware_data.get("order_service")

    order = await order_service.get_order_by_id(order_id)
    server = await get_server(db_session, order.proxies[0].server_id)
    if server.proxy_type == ServerType.mobile and server.proxy_privacy == ServerPrivacy.private:
        mobile_private = True
    else:
        mobile_private = False

    return {"proxy_is_mobile_private": mobile_private}
